package org.anupta.game.server.inter.client;

import org.anupta.game.server.inter.packet.InterPacket;
import org.anupta.game.server.inter.packet.connect.Connect;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.IoSession;

public class InterClient {
	private IoSession session = null;
	private InterParser parser = null;
	
	public InterClient(IoSession session){
		setSession(session);
		setParser(new InterParser(this));
		new Connect(this);
	}
	
	public void parse(IoBuffer message){
		parser.parseBuffer(message);
	}
	
	public void quit(){
		//TODO: Kick all player
		session.close(true);
	}

	public IoSession getSession() {
		return session;
	}

	public void setSession(IoSession session) {
		this.session = session;
	}

	public InterParser getParser() {
		return parser;
	}

	public void setParser(InterParser parser) {
		this.parser = parser;
	}
	
	public String getRemoteIp(){
		return session.getRemoteAddress().toString();
	}
	
	public void send(InterPacket packet){
		session.write(packet.packetOut.flip());
	}
}
